package org.come.starcard;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.math.BigDecimal;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

import com.updateNew.MyIsif;
import org.come.entity.Goodstable;
import org.come.until.CutButtonImage;
import org.come.until.FormsManagement;
import org.come.until.GoodsListFromServerUntil;

import com.tool.btn.FormsOnOffBtn;
import com.tool.tcpimg.UIUtils;

/***
 * 斗转星移主面板
 * <p>
 * Title : JpanelStarTransferMain
 * </p>
 *
 * @author : HGC
 * @date : 2019年8月14日 上午9:51:12
 * @version : 1.0.0
 */
public class JpanelStarTransferMain extends JPanel {

    /**
     * starCardImgLeft左侧星卡图片<br>
     * starArrayImgLeft左侧星阵图片<br>
     * starArrayNameLeft左侧星阵名称<br>
     * starCardImgRight右侧星卡图片<br>
     * starArrayImgRight右侧星阵图片<br>
     * starArrayNameRight右侧星阵名称<br>
     */
    private JLabel starCardImgLeft, starArrayImgLeft, starArrayNameLeft, starCardImgRight, starArrayImgRight,
            starArrayNameRight;

    /**
     * starCardLab星卡9个格子<br>
     * radioLabLeft星卡左侧勾选框4个格子<br>
     * starArrayAttributeLabLeft星卡左侧属性4个格子<br>
     * radioLabRight星卡右侧勾选框4个格子<br>
     * starArrayAttributeLabRight星卡右侧属性4个格子<br>
     */
    private JLabel[] starCardLab, radioLabLeft, starArrayAttributeLabLeft, radioLabRight, starArrayAttributeLabRight;

    /**
     * yesBtn确认转移按钮<br>
     */
    private BtnStarCard yesBtn;

    private BigDecimal chooseOneId, chooseTwoId;

    public JpanelStarTransferMain() {
        String style = MyIsif.getStyle();
        if ("水墨UI".equals(style)) {
            //
            this.setPreferredSize(new Dimension(562, 435));
            setOpaque(false);
            setLayout(null);

            // 关闭按钮事件
            FormsOnOffBtn offBtn = new FormsOnOffBtn("inkImg/button/1.png", 1, 97);
            offBtn.setBounds(537, 0, 25, 25);
            this.add(offBtn);

            getStarCardLab();
            getStarArrayAttributeLabLeft();
            getStarArrayAttributeLabRight();
            getStarArrayImgLeft();
            getStarArrayImgRight();
            getStarArrayNameLeft();
            getStarArrayNameRight();
            getStarCardImgLeft();
            getStarCardImgRight();
            getRadioLabLeft();
            getRadioLabRight();
            getYesBtn();
        }else {
            this.setPreferredSize(new Dimension(540, 497));
            setOpaque(false);
            setLayout(null);

            // 关闭按钮事件
            FormsOnOffBtn offBtn = new FormsOnOffBtn("img/xy2uiimg/8_jpg.button.btn_close.jpg", 1, 97);
            offBtn.setBounds(515, 0, 23, 23);
            this.add(offBtn);

            getStarCardLab();
            getStarArrayAttributeLabLeft();
            getStarArrayAttributeLabRight();
            getStarArrayImgLeft();
            getStarArrayImgRight();
            getStarArrayNameLeft();
            getStarArrayNameRight();
            getStarCardImgLeft();
            getStarCardImgRight();
            getRadioLabLeft();
            getRadioLabRight();
            getYesBtn();
        }
    }

    /** 展示当前星卡星阵属性 type:0左侧/1右侧 */
    public void showStarCardAttribute(int type, String[] values, Goodstable goodstable) {
        if (goodstable == null) {
            FormsManagement.HideForm(97);
        }
        String[] starArray = { "青帝宫", "黄帝宫", "白帝宫", "黑帝宫" };
        if (type == 0) {
            chooseOneId = goodstable.getRgid();
            starCardImgLeft.setIcon(GoodsListFromServerUntil.imgpathAdaptive(goodstable.getSkin(), 55, 53));
            starArrayImgLeft.setIcon(CutButtonImage.getImage("inkImg/old/skill/" + values[1] + ".png", 55, 53));
            starArrayNameLeft.setText(values[1]);
            // 顺序：赤帝宫=青帝宫=黄帝宫=白帝宫=黑帝宫(其中赤帝宫不参与斗转星移)
            for (int i = 4; i < values.length; i++) {
                radioLabLeft[i - 4].setIcon(null);
                starArrayAttributeLabLeft[i - 4].setText(starArray[i - 4] + " " + values[i]);
            }
        } else {
            if (goodstable == null && values == null) {
                chooseTwoId = null;
                starCardImgRight.setIcon(null);
                starArrayImgRight.setIcon(null);
                starArrayNameRight.setText("");
                // 顺序：赤帝宫=青帝宫=黄帝宫=白帝宫=黑帝宫(其中赤帝宫不参与斗转星移)
                for (int i = 0; i < radioLabRight.length; i++) {
                    radioLabRight[i].setIcon(null);
                    starArrayAttributeLabRight[i].setText("");
                }
            } else {
                chooseTwoId = goodstable.getRgid();
                starCardImgRight.setIcon(GoodsListFromServerUntil.imgpathAdaptive(goodstable.getSkin(), 55, 53));
                starArrayImgRight.setIcon(CutButtonImage.getImage("inkImg/old/skill/" + values[1] + ".png", 55, 53));
                starArrayNameRight.setText(values[1]);
                // 顺序：赤帝宫=青帝宫=黄帝宫=白帝宫=黑帝宫(其中赤帝宫不参与斗转星移)

                for (int i = 4; i < values.length; i++) {
                    radioLabRight[i - 4].setIcon(null);
                    starArrayAttributeLabRight[i - 4].setText(starArray[i - 4] + " " + values[i]);
                }
            }
        }
    }

    private ImageIcon iconBack;

    @Override
    protected void paintComponent(Graphics g) {
        String style = MyIsif.getStyle();
        if ("水墨UI".equals(style)) {
            //
            super.paintComponent(g);
            if (iconBack == null) {
                iconBack = new ImageIcon("inkImg/background/S97.png");
            }
            g.drawImage(iconBack.getImage(), 0, 0, 562, 435, this);
            GoodsListFromServerUntil.drawStarArray(g, 55, 345);
        } else {
            super.paintComponent(g);
            if (iconBack == null) {
                iconBack = new ImageIcon("img/xy2uiimg/斗转星移_540,h497.png");
            }
            g.drawImage(iconBack.getImage(), 0, 0, 540, 497, this);
            GoodsListFromServerUntil.drawStarArray(g, 40, 392);
        }
    }
    public ImageIcon getIconBack() {
        return iconBack;
    }

    public void setIconBack(ImageIcon iconBack) {
        this.iconBack = iconBack;
    }

    public JLabel[] getStarCardLab() {
        String style = MyIsif.getStyle();
        if ("水墨UI".equals(style)) {
            //
            if (starCardLab == null) {
                starCardLab = new JLabel[9];
                for (int i = 0; i < starCardLab.length; i++) {
                    starCardLab[i] = new JLabel();
                    starCardLab[i].setBounds(55 + i * 51, 345, 50, 50);
                    starCardLab[i].setOpaque(false);
                    starCardLab[i].addMouseListener(new MouseListenerStarTransferMain(i, this));
                    this.add(starCardLab[i]);
                }
            }
            return starCardLab;
        }else{
            if (starCardLab == null) {
                starCardLab = new JLabel[9];
                for (int i = 0; i < starCardLab.length; i++) {
                    starCardLab[i] = new JLabel();
                    starCardLab[i].setBounds(40 + i * 51, 392, 50, 50);
                    starCardLab[i].setOpaque(false);
                    starCardLab[i].addMouseListener(new MouseListenerStarTransferMain(i, this));
                    this.add(starCardLab[i]);
                }
            }
            return starCardLab;
        }
    }

    public void setStarCardLab(JLabel[] starCardLab) {
        this.starCardLab = starCardLab;
    }

    public JLabel getStarCardImgLeft() {
        String style = MyIsif.getStyle();
        if ("水墨UI".equals(style)) {
            //
            if (starCardImgLeft == null) {
                starCardImgLeft = new JLabel();
                starCardImgLeft.setBounds(133, 74, 55, 53);
                starCardImgLeft.setOpaque(false);
                this.add(starCardImgLeft);
            }
            return starCardImgLeft;
        }else{
            if (starCardImgLeft == null) {
                starCardImgLeft = new JLabel();
                starCardImgLeft.setBounds(118, 112, 55, 53);
                starCardImgLeft.setOpaque(false);
                this.add(starCardImgLeft);
            }
            return starCardImgLeft;
        }
    }

    public void setStarCardImgLeft(JLabel starCardImgLeft) {
        this.starCardImgLeft = starCardImgLeft;
    }

    public JLabel getStarArrayImgLeft() {
        String style = MyIsif.getStyle();
        if ("水墨UI".equals(style)) {
            //
            if (starArrayImgLeft == null) {
                starArrayImgLeft = new JLabel("", SwingConstants.CENTER);
                starArrayImgLeft.setBounds(205, 74, 30, 25);
                starArrayImgLeft.setOpaque(false);
                this.add(starArrayImgLeft);
            }
            return starArrayImgLeft;
        }else{
            if (starArrayImgLeft == null) {
                starArrayImgLeft = new JLabel("", SwingConstants.CENTER);
                starArrayImgLeft.setBounds(195, 118, 30, 25);
                starArrayImgLeft.setOpaque(false);
                this.add(starArrayImgLeft);
            }
            return starArrayImgLeft;
        }
    }

    public void setStarArrayImgLeft(JLabel starArrayImgLeft) {
        this.starArrayImgLeft = starArrayImgLeft;
    }

    public JLabel getStarArrayNameLeft() {
        String style = MyIsif.getStyle();
        if ("水墨UI".equals(style)) {
            //
            if (starArrayNameLeft == null) {
                starArrayNameLeft = new JLabel("", SwingConstants.CENTER);
                starArrayNameLeft.setBounds(195, 100, 55, 20);
                starArrayNameLeft.setOpaque(false);
                // starArrayNameLeft.setForeground(Color);
                starArrayNameLeft.setFont(UIUtils.TEXT_FONT1);
                this.add(starArrayNameLeft);
            }
            return starArrayNameLeft;
        }else{
            if (starArrayNameLeft == null) {
                starArrayNameLeft = new JLabel("", SwingConstants.CENTER);
                starArrayNameLeft.setBounds(183, 148, 55, 20);
                starArrayNameLeft.setOpaque(false);
                // starArrayNameLeft.setForeground(Color);
                starArrayNameLeft.setFont(UIUtils.TEXT_FONT1);
                this.add(starArrayNameLeft);
            }
            return starArrayNameLeft;
        }
    }

    public void setStarArrayNameLeft(JLabel starArrayNameLeft) {
        this.starArrayNameLeft = starArrayNameLeft;
    }

    public JLabel getStarCardImgRight() {
        String style = MyIsif.getStyle();
        if ("水墨UI".equals(style)) {
            //
            if (starCardImgRight == null) {
                starCardImgRight = new JLabel();
                starCardImgRight.setBounds(381, 74, 55, 53);
                starCardImgRight.setOpaque(false);
                this.add(starCardImgRight);
            }
            return starCardImgRight;
        }else{
            if (starCardImgRight == null) {
                starCardImgRight = new JLabel();
                starCardImgRight.setBounds(366, 112, 55, 53);
                starCardImgRight.setOpaque(false);
                this.add(starCardImgRight);
            }
            return starCardImgRight;
        }
    }

    public void setStarCardImgRight(JLabel starCardImgRight) {
        this.starCardImgRight = starCardImgRight;
    }

    public JLabel getStarArrayImgRight() {
        String style = MyIsif.getStyle();
        if ("水墨UI".equals(style)) {
            //
            if (starArrayImgRight == null) {
                starArrayImgRight = new JLabel("", SwingConstants.CENTER);
                starArrayImgRight.setBounds(335, 74, 30, 25);
                starArrayImgRight.setOpaque(false);
                this.add(starArrayImgRight);
            }
            return starArrayImgRight;
        }else{
            if (starArrayImgRight == null) {
                starArrayImgRight = new JLabel("", SwingConstants.CENTER);
                starArrayImgRight.setBounds(315, 118, 30, 25);
                starArrayImgRight.setOpaque(false);
                this.add(starArrayImgRight);
            }
            return starArrayImgRight;
        }
    }

    public void setStarArrayImgRight(JLabel starArrayImgRight) {
        this.starArrayImgRight = starArrayImgRight;
    }

    public JLabel getStarArrayNameRight() {
        String style = MyIsif.getStyle();
        if ("水墨UI".equals(style)) {
            //
            if (starArrayNameRight == null) {
                starArrayNameRight = new JLabel("", SwingConstants.CENTER);
                starArrayNameRight.setBounds(322, 100, 55, 20);
                starArrayNameRight.setOpaque(false);
                // starArrayNameRight.setForeground(UIUtils.getColor("while"));
                starArrayNameRight.setFont(UIUtils.TEXT_FONT1);
                this.add(starArrayNameRight);
            }
            return starArrayNameRight;
        }else{
            if (starArrayNameRight == null) {
                starArrayNameRight = new JLabel("", SwingConstants.CENTER);
                starArrayNameRight.setBounds(300, 148, 55, 20);
                starArrayNameRight.setOpaque(false);
                // starArrayNameRight.setForeground(UIUtils.getColor("while"));
                starArrayNameRight.setFont(UIUtils.TEXT_FONT1);
                this.add(starArrayNameRight);
            }
            return starArrayNameRight;
        }
    }

    public void setStarArrayNameRight(JLabel starArrayNameRight) {
        this.starArrayNameRight = starArrayNameRight;
    }

    public JLabel[] getRadioLabLeft() {
        String style = MyIsif.getStyle();
        if ("水墨UI".equals(style)) {
            //
            if (radioLabLeft == null) {
                radioLabLeft = new JLabel[4];

                class Mlistener extends MouseAdapter {
                    private int i;

                    public Mlistener(int i) {
                        this.i = i;
                    }

                    @Override
                    public void mousePressed(MouseEvent e) {
                        for (int i = 0; i < radioLabLeft.length; i++) {
                            if (radioLabLeft[i].getIcon() != null && i != this.i) {
                                radioLabLeft[i].setIcon(null);
                            }
                        }
                        if (radioLabLeft[i].getIcon() == null)
                            radioLabLeft[i].setIcon(CutButtonImage.getImage("img/xy2uiimg/选中w7,h7px.png", 7, 7));
                    }
                }
                for (int i = 0; i < radioLabLeft.length; i++) {
                    radioLabLeft[i] = new JLabel();
                    radioLabLeft[i].setHorizontalAlignment(SwingConstants.CENTER);
                    radioLabLeft[i].setVerticalAlignment(SwingConstants.CENTER);
                    radioLabLeft[i].setBounds(58, 146 + i * 39, 20, 20);
                    radioLabLeft[i].setIcon(CutButtonImage.getImage("img/xy2uiimg/选中w7,h7px.png", 7, 7));
                    radioLabLeft[i].addMouseListener(new Mlistener(i));
                    this.add(radioLabLeft[i]);
                }
            }
            return radioLabLeft;
        }else{
            if (radioLabLeft == null) {
                radioLabLeft = new JLabel[4];

                class Mlistener extends MouseAdapter {
                    private int i;

                    public Mlistener(int i) {
                        this.i = i;
                    }

                    @Override
                    public void mousePressed(MouseEvent e) {
                        for (int i = 0; i < radioLabLeft.length; i++) {
                            if (radioLabLeft[i].getIcon() != null && i != this.i) {
                                radioLabLeft[i].setIcon(null);
                            }
                        }
                        if (radioLabLeft[i].getIcon() == null)
                            radioLabLeft[i].setIcon(CutButtonImage.getImage("img/xy2uiimg/选中w7,h7px.png", 7, 7));
                    }
                }
                for (int i = 0; i < radioLabLeft.length; i++) {
                    radioLabLeft[i] = new JLabel();
                    radioLabLeft[i].setHorizontalAlignment(SwingConstants.CENTER);
                    radioLabLeft[i].setVerticalAlignment(SwingConstants.CENTER);
                    radioLabLeft[i].setBounds(54, 186 + i * 39, 20, 20);
                    radioLabLeft[i].setIcon(CutButtonImage.getImage("img/xy2uiimg/选中w7,h7px.png", 7, 7));
                    radioLabLeft[i].addMouseListener(new Mlistener(i));
                    this.add(radioLabLeft[i]);
                }
            }
            return radioLabLeft;
        }
    }

    public void setRadioLabLeft(JLabel[] radioLabLeft) {
        this.radioLabLeft = radioLabLeft;
    }

    public JLabel[] getStarArrayAttributeLabLeft() {
        String style = MyIsif.getStyle();
        if ("水墨UI".equals(style)) {
            //
            if (starArrayAttributeLabLeft == null) {
                starArrayAttributeLabLeft = new JLabel[4];
                for (int i = 0; i < starArrayAttributeLabLeft.length; i++) {
                    starArrayAttributeLabLeft[i] = new JLabel();
                    starArrayAttributeLabLeft[i].setBounds(84, 141 + i * 39, 184, 30);
                    starArrayAttributeLabLeft[i].setOpaque(false);
                    starArrayAttributeLabLeft[i].setForeground(Color.white);
                    starArrayAttributeLabLeft[i].setFont(UIUtils.TEXT_FONT1);
                    this.add(starArrayAttributeLabLeft[i]);
                }
            }
            return starArrayAttributeLabLeft;
        }else{
            if (starArrayAttributeLabLeft == null) {
                starArrayAttributeLabLeft = new JLabel[4];
                for (int i = 0; i < starArrayAttributeLabLeft.length; i++) {
                    starArrayAttributeLabLeft[i] = new JLabel();
                    starArrayAttributeLabLeft[i].setBounds(74, 181 + i * 39, 184, 30);
                    starArrayAttributeLabLeft[i].setOpaque(false);
                    starArrayAttributeLabLeft[i].setForeground(Color.white);
                    starArrayAttributeLabLeft[i].setFont(UIUtils.TEXT_FONT1);
                    this.add(starArrayAttributeLabLeft[i]);
                }
            }
            return starArrayAttributeLabLeft;
        }
    }

    public void setStarArrayAttributeLabLeft(JLabel[] starArrayAttributeLabLeft) {
        this.starArrayAttributeLabLeft = starArrayAttributeLabLeft;
    }

    public JLabel[] getRadioLabRight() {
        String style = MyIsif.getStyle();
        if ("水墨UI".equals(style)) {
            //
            if (radioLabRight == null) {
                radioLabRight = new JLabel[4];
                class Mlistener extends MouseAdapter {
                    private int i;

                    public Mlistener(int i) {
                        this.i = i;
                    }

                    @Override
                    public void mousePressed(MouseEvent e) {

                        for (int i = 0; i < radioLabRight.length; i++) {
                            if (radioLabRight[i].getIcon() != null && i != this.i) {
                                radioLabRight[i].setIcon(null);
                            }
                        }
                        if (radioLabRight[i].getIcon() == null)
                            radioLabRight[i].setIcon(CutButtonImage.getImage("img/xy2uiimg/选中w7,h7px.png", 7, 7));
                    }
                }
                for (int i = 0; i < radioLabRight.length; i++) {
                    radioLabRight[i] = new JLabel("", SwingConstants.CENTER);
                    radioLabRight[i].setBounds(307, 148 + i * 39, 17, 17);
                    // radioLabRight[i].setIcon(CutButtonImage.getImage("img/xy2uiimg/选中w7,h7px.png",
                    // 7, 7));
                    radioLabRight[i].addMouseListener(new Mlistener(i));
                    this.add(radioLabRight[i]);
                }
            }
            return radioLabRight;
        }else{
            if (radioLabRight == null) {
                radioLabRight = new JLabel[4];
                class Mlistener extends MouseAdapter {
                    private int i;

                    public Mlistener(int i) {
                        this.i = i;
                    }

                    @Override
                    public void mousePressed(MouseEvent e) {

                        for (int i = 0; i < radioLabRight.length; i++) {
                            if (radioLabRight[i].getIcon() != null && i != this.i) {
                                radioLabRight[i].setIcon(null);
                            }
                        }
                        if (radioLabRight[i].getIcon() == null)
                            radioLabRight[i].setIcon(CutButtonImage.getImage("img/xy2uiimg/选中w7,h7px.png", 7, 7));
                    }
                }
                for (int i = 0; i < radioLabRight.length; i++) {
                    radioLabRight[i] = new JLabel("", SwingConstants.CENTER);
                    radioLabRight[i].setBounds(286, 186 + i * 39, 17, 17);
                    // radioLabRight[i].setIcon(CutButtonImage.getImage("img/xy2uiimg/选中w7,h7px.png",
                    // 7, 7));
                    radioLabRight[i].addMouseListener(new Mlistener(i));
                    this.add(radioLabRight[i]);
                }
            }
            return radioLabRight;
        }
    }

    public void setRadioLabRight(JLabel[] radioLabRight) {
        this.radioLabRight = radioLabRight;
    }

    public JLabel[] getStarArrayAttributeLabRight() {
        String style = MyIsif.getStyle();
        if ("水墨UI".equals(style)) {
            //
            if (starArrayAttributeLabRight == null) {
                starArrayAttributeLabRight = new JLabel[4];
                for (int i = 0; i < starArrayAttributeLabRight.length; i++) {
                    starArrayAttributeLabRight[i] = new JLabel();
                    starArrayAttributeLabRight[i].setBounds(330, 143 + i * 39, 184, 30);
                    starArrayAttributeLabRight[i].setOpaque(false);
                    starArrayAttributeLabRight[i].setForeground(Color.white);
                    starArrayAttributeLabRight[i].setFont(UIUtils.TEXT_FONT1);
                    this.add(starArrayAttributeLabRight[i]);
                }
            }
            return starArrayAttributeLabRight;
        }else{
            if (starArrayAttributeLabRight == null) {
                starArrayAttributeLabRight = new JLabel[4];
                for (int i = 0; i < starArrayAttributeLabRight.length; i++) {
                    starArrayAttributeLabRight[i] = new JLabel();
                    starArrayAttributeLabRight[i].setBounds(306, 181 + i * 39, 184, 30);
                    starArrayAttributeLabRight[i].setOpaque(false);
                    starArrayAttributeLabRight[i].setForeground(Color.white);
                    starArrayAttributeLabRight[i].setFont(UIUtils.TEXT_FONT1);
                    this.add(starArrayAttributeLabRight[i]);
                }
            }
            return starArrayAttributeLabRight;
        }
    }

    public void setStarArrayAttributeLabRight(JLabel[] starArrayAttributeLabRight) {
        this.starArrayAttributeLabRight = starArrayAttributeLabRight;
    }

    public BtnStarCard getYesBtn() {
        String style = MyIsif.getStyle();
        if ("水墨UI".equals(style)) {
            //
            if (yesBtn == null) {
                yesBtn = new BtnStarCard("inkImg/button/75.png", 1, UIUtils.COLOR_BLACK, UIUtils.TEXT_HY88, "确认转移", 40,
                        this);
                yesBtn.setBounds(245, 307, 82, 26);
                this.add(yesBtn);
            }
            return yesBtn;
        }else{
            if (yesBtn == null) {
                yesBtn = new BtnStarCard("inkImg/hongmu/1_png.button.btn_xy.png", 1, UIUtils.COLOR_BTNPUTONG2, UIUtils.TEXT_HY88, "确认转移", 40,
                        this);
                yesBtn.setBounds(215, 347, 80, 26);
                this.add(yesBtn);
            }
            return yesBtn;
        }
    }

    public void setYesBtn(BtnStarCard yesBtn) {
        this.yesBtn = yesBtn;
    }

    public BigDecimal getChooseOneId() {
        return chooseOneId;
    }

    public void setChooseOneId(BigDecimal chooseOneId) {
        this.chooseOneId = chooseOneId;
    }

    public BigDecimal getChooseTwoId() {
        return chooseTwoId;
    }

    public void setChooseTwoId(BigDecimal chooseTwoId) {
        this.chooseTwoId = chooseTwoId;
    }

}
